#pragma once
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <mutex>
#include <string>
#include <cstdint>
#include <utility>

namespace HAL
{
    class PWM_Master
    {
        public:
            PWM_Master(const std::string &dev, uint32_t freq = 50, float duty = 50);
            ~PWM_Master();
            int SetPWMFreq(uint32_t freq);
            int SetPWMDuty(float duty); // 0~100
            int SetPWMEnable(bool enable);
            int SetPWMPeriod(uint32_t period);
            int SetPWMPolarity(bool polarity);  
        private:
            int ConfigPWM(const std::string &attr, const std::string &val);
            std::pair<int, int> GetPWMChipNumAndPWMNum(const std::string &path);
        private:
            std::string dev;
            std::mutex mtx;
            long basePeriod;
            int chipNum;
            int pwmNum;
    };

}